#ifndef MSGPLUG_H
#define MSGPLUG_H

#include <stdarg.h>

class MsgPlug;

class MsgPlugs
{
	public:
		MsgPlugs();
		~MsgPlugs();

		bool8 add(MsgPlug*);

		int32 getLen(int32 index);			// len or 0
		char* getText(int32 index);			// null-term string (never NULL)
		void reset(int32 index);

		void setValue(int32 index, ...);	// no type or #args checking!!

	protected:
		int32		numPlugs;
		MsgPlug**	plugs;
		char		empty;
};

class MsgPlug
{
	public:
		MsgPlug() { }
		virtual ~MsgPlug() { }

		virtual int32 getLen() = 0;
		virtual char* getText() = 0;	// *never* to be released by caller
		virtual void setValue(va_list) = 0;
		virtual void reset() = 0;
};

class NullTermCharArrayMsgPlug : public MsgPlug
{
	public:
		NullTermCharArrayMsgPlug(
			char* NullTermNeverNullPointer,
			int32 maxlenPlusNull);

		int32 getLen() { return len; }
		char* getText() { return str; }
		void setValue(va_list /* char* */);
		void reset();

	protected:
		NullTermCharArrayMsgPlug() { str = (char*)0; len = maxlen = 0; }

	protected:
		char* str;
		int32 len, maxlen;
};

class Int32MsgPlug : public NullTermCharArrayMsgPlug
{
	public:
		Int32MsgPlug();

		int32 getLen();
		char* getText();
		void setValue(va_list /* int32 */);
		void reset();

	protected:
		void convert();

	protected:
		enum Constants { MAXASCIIINT = 11 };
		char asciiint[MAXASCIIINT + 1];
		int32 val;
		bool8 converted;
};

class MoneyMsgPlug : public NullTermCharArrayMsgPlug
{
	public:
		MoneyMsgPlug( char* );
		~MoneyMsgPlug();

		int32 getLen();
		char* getText();
		void setValue(va_list /* int32 */);
		void reset();

	protected:
		void convert();

	protected:
		enum Constants { MAXMONEY = 16 };
		char money[MAXMONEY + 1];
		int32 val;
		bool8 converted;
		char *currency;
		int32 curL;			// currency Length
};

#endif